<template>
	<div class="padding">
		<div class="f-between">
			<h3>养老机构等级评定正式文件复印件</h3>
		</div>
		<div class="mt12" v-if="!isDetail">
			<AplidUpload
				v-model="modelData.imageList"
				listType="picture-card"
				:showFileList="false"
				:fileType="uploadType.fileMetaType"
				name="养老机构等级评定正式文件复印件"
				uploadTip="上传养老机构等级评定正式文件复印件"
				:limit="1"
				:multiple="false"
				:disabled="isDetail"
				@change="uploadChange"
			></AplidUpload>
		</div>
	</div>
</template>

<script setup lang="ts">
import AplidUpload from '@/components/AplidCrud/src/AplidUpload/index.vue'
import FileSaver from 'file-saver'
import apiMod from '@/apiMod/index'
import FileList from '@/components/AplidCrud/src/AplidUpload/PreviewImg/index.vue'
import { uploadType } from '@/utils/util'

const props = defineProps<{
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	activeName?: string
}>()
let modelData = reactive({ imageList: '' })

let newCaseId = ref('')
const addSave = async () => {
	let date = props.params.belongDate.replace('年', '-').replace('月', '-').split('-')
	let params0 = {
		applyYear: date[0],
		applyMonth: date[1],
		dataContent: { imageList: modelData.imageList },
		dataResults: { imageList: modelData.imageList },
		fromId: props.editData.formId,
		fromType: props.activeName,
		tableTemplateId: props.activeName,
		projectId: props.params.subsidyProjectId,
	}
	let res = await apiMod.view_formResults_add(params0)
	newCaseId.value = res.data
}

const eidtSave = () => {
	let query = {
		id: props.editData.result_case_id || newCaseId.value,
		dataContent: { imageList: modelData.imageList },
		dataResults: { imageList: modelData.imageList },
		fromId: props.editData.formId,
		fromType: props.activeName,
		tableTemplateId: props.activeName,
		projectId: props.params.subsidyProjectId,
	}
	apiMod.view_formResults_edit(query).then((res) => {
		ElMessage.success('修改成功')
	})
}
const uploadChange = (data) => {
	eidtSave()
}
onMounted(() => {
	if (!props.params) {
		return
	}
	// 没有id就进行第一次保存
	if (!props.editData.result_case_id) {
		addSave()
	}
	modelData = props.editData
})
</script>
<style scoped lang="scss">
:deep(.el-upload--picture-card) {
	width: 100%;
	height: 100%;
	max-height: 250px;
}
</style>
